﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketDOHS
{
    public partial class CondDent2 : Form
    {
        private TextBox txtFocus;        

        public CondDent2()
        {
            InitializeComponent();
        }

        private void btnVoltar_Click(object sender, EventArgs e)
        {
            FormsMethods.prevForm();
        }

        private void btnLimp_Click(object sender, EventArgs e)
        {
            Limpar_txt_Form();
            txtCoroa21.Focus();
        }

        private void txtCoroaFocus(object sender, EventArgs e)
        {
            btn0.Enabled = true;
            btn1.Enabled = true;
            btn2.Enabled = true;
            btn3.Enabled = true;
            btn4.Enabled = true;
            btn5.Enabled = true;
            btn6.Enabled = true;
            btn7.Enabled = true;
            btn8.Enabled = true;
            btnT.Enabled = true;
            btnA.Enabled = false;
            btnB.Enabled = false;
            btnC.Enabled = false;
            btnD.Enabled = false;
            btnE.Enabled = false;
            btnF.Enabled = false;
            btnG.Enabled = false;
            btnP.Enabled = false;
            txtFocus = (TextBox)sender;
        }

        private void BotoesFalso()
        {
            btn0.Enabled = false;
            btn1.Enabled = false;
            btn2.Enabled = false;
            btn3.Enabled = false;
            btn4.Enabled = false;
            btn5.Enabled = false;
            btn6.Enabled = false;
            btn7.Enabled = false;
            btn8.Enabled = false;
            btn9.Enabled = false;
            btnA.Enabled = false;
            btnB.Enabled = false;
            btnC.Enabled = false;
            btnD.Enabled = false;
            btnE.Enabled = false;
            btnF.Enabled = false;
            btnG.Enabled = false;
            btnP.Enabled = false;
            btnT.Enabled = false;
        }

        private void txtRaizFocus(object sender, EventArgs e)
        {
            BotoesFalso();
            txtFocus = (TextBox)sender;
            ValidacaoCodRaiz((TextBox)sender);
        }

        public void txtTratamentoFocus(object sender, EventArgs e)
        {
            BotoesFalso();
            txtFocus = (TextBox)sender;
            ValidacaoCodTratamento((TextBox)sender);
        }

        private void WriteTextBox(object sender, EventArgs e)
        {
            FormsMethods.WriteTextBox((Button)sender, txtFocus, this);
        }

        private void ValidacaoCodRaiz(TextBox sender)
        {
            string codCoroa = "";

            switch (sender.Name)
            {
                case "txtRaiz28":
                    codCoroa = txtCoroa28.Text;
                    break;
                case "txtRaiz27":
                    codCoroa = txtCoroa27.Text;
                    break;
                case "txtRaiz26":
                    codCoroa = txtCoroa26.Text;
                    break;
                case "txtRaiz25":
                    codCoroa = txtCoroa25.Text;
                    break;
                case "txtRaiz24":
                    codCoroa = txtCoroa24.Text;
                    break;
                case "txtRaiz23":
                    codCoroa = txtCoroa23.Text;
                    break;
                case "txtRaiz22":
                    codCoroa = txtCoroa22.Text;
                    break;
                case "txtRaiz21":
                    codCoroa = txtCoroa21.Text;
                    break;
            }
            if (codCoroa == "4" || codCoroa == "5" || codCoroa == "8" || codCoroa == "E")
            {
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn3.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
        }

        private void ValidacaoCodTratamento(TextBox sender)
        {
            string codCoroa = "";
            string codRaiz = "";

            switch (sender.Name)
            {
                case "txtTrat28":
                    codCoroa = txtCoroa28.Text;
                    codRaiz = txtRaiz28.Text;
                    break;
                case "txtTrat27":
                    codCoroa = txtCoroa27.Text;
                    codRaiz = txtRaiz27.Text;
                    break;
                case "txtTrat26":
                    codCoroa = txtCoroa26.Text;
                    codRaiz = txtRaiz26.Text;
                    break;
                case "txtTrat25":
                    codCoroa = txtCoroa25.Text;
                    codRaiz = txtRaiz25.Text;
                    break;
                case "txtTrat24":
                    codCoroa = txtCoroa24.Text;
                    codRaiz = txtRaiz24.Text;
                    break;
                case "txtTrat23":
                    codCoroa = txtCoroa23.Text;
                    codRaiz = txtRaiz23.Text;
                    break;
                case "txtTrat22":
                    codCoroa = txtCoroa22.Text;
                    codRaiz = txtRaiz22.Text;
                    break;
                case "txtTrat21":
                    codCoroa = txtCoroa21.Text;
                    codRaiz = txtRaiz21.Text;
                    break;
            }

            if (codCoroa == "1" || codCoroa == "2" || codCoroa == "B" || codCoroa == "C")
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn5.Enabled = true;
                btn6.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else if (codCoroa == "3" || codCoroa == "D")
            {
                btn0.Enabled = true;
                btn9.Enabled = true;
                if (codRaiz == "0" || codRaiz == "8")
                {
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "1" || codRaiz == "2")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                }
                else if (codRaiz == "3")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "7")
                {
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else
                    btnP.Enabled = true;
            }
            else if (codCoroa == "4" || codCoroa == "5" || codCoroa == "8" || codCoroa == "E")
            {
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else if (codCoroa == "6" || codCoroa == "F")
            {
                btn0.Enabled = true;
                btn9.Enabled = true;
                if (codRaiz == "0")
                {
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "1" || codRaiz == "2")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                }
                else if (codRaiz == "3")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "7")
                {
                    btn0.Enabled = true;
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn3.Enabled = true;
                    btn4.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btn9.Enabled = true;
                    btnA.Enabled = true;
                    btnB.Enabled = true;
                    btnC.Enabled = true;
                    btnD.Enabled = true;
                    btnE.Enabled = true;
                    btnF.Enabled = true;
                    btnP.Enabled = true;
                }
            }
            else if (codCoroa == "7" || codCoroa == "G")
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn3.Enabled = true;
                btn4.Enabled = true;
                btn5.Enabled = true;
                btn6.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
                btnA.Enabled = true;
                btnB.Enabled = true;
                btnC.Enabled = true;
                btnD.Enabled = true;
                btnE.Enabled = true;
                btnF.Enabled = true;
                btnP.Enabled = true;
            }
        }

        #region CoroaChanged

        private void txtCoroa21_TextChanged(object sender, EventArgs e)
        {
            txtRaiz21.Text = "0";
            txtTrat21.Text = "0";
            txtRaiz21.Focus();
        }

        private void txtCoroa22_TextChanged(object sender, EventArgs e)
        {
            txtRaiz22.Text = "0";
            txtTrat22.Text = "0";
            txtRaiz22.Focus();
        }

        private void txtCoroa23_TextChanged(object sender, EventArgs e)
        {
            txtRaiz23.Text = "0";
            txtTrat23.Text = "0";
            txtRaiz23.Focus();
        }

        private void txtCoroa24_TextChanged(object sender, EventArgs e)
        {
            txtRaiz24.Text = "0";
            txtTrat24.Text = "0";
            txtRaiz24.Focus();
        }

        private void txtCoroa25_TextChanged(object sender, EventArgs e)
        {
            txtRaiz25.Text = "0";
            txtTrat25.Text = "0";
            txtRaiz25.Focus();
        }

        private void txtCoroa26_TextChanged(object sender, EventArgs e)
        {
            txtRaiz26.Text = "0";
            txtTrat26.Text = "0";
            txtRaiz26.Focus();
        }

        private void txtCoroa27_TextChanged(object sender, EventArgs e)
        {
            txtRaiz27.Text = "0";
            txtTrat27.Text = "0";
            txtRaiz27.Focus();
        }

        private void txtCoroa28_TextChanged(object sender, EventArgs e)
        {
            txtRaiz28.Text = "0";
            txtTrat28.Text = "0";
            txtRaiz28.Focus();
        }

        #endregion

        #region RaizChanged

        private void txtRaiz28_TextChanged(object sender, EventArgs e)
        {
            txtTrat28.Text = "0";
            txtTrat28.Focus();
        }

        private void txtRaiz27_TextChanged(object sender, EventArgs e)
        {
            txtTrat27.Text = "0";
            txtTrat27.Focus();
        }

        private void txtRaiz26_TextChanged(object sender, EventArgs e)
        {
            txtTrat26.Text = "0";
            txtTrat26.Focus();
        }

        private void txtRaiz25_TextChanged(object sender, EventArgs e)
        {
            txtTrat25.Text = "0";
            txtTrat25.Focus();
        }

        private void txtRaiz24_TextChanged(object sender, EventArgs e)
        {
            txtTrat24.Text = "0";
            txtTrat24.Focus();
        }

        private void txtRaiz23_TextChanged(object sender, EventArgs e)
        {
            txtTrat23.Text = "0";
            txtTrat23.Focus();
        }

        private void txtRaiz22_TextChanged(object sender, EventArgs e)
        {
            txtTrat22.Text = "0";
            txtTrat22.Focus();
        }

        private void txtRaiz21_TextChanged(object sender, EventArgs e)
        {
            txtTrat21.Text = "0";
            txtTrat21.Focus();
        }

        #endregion

        #region TratamentoChanged

            private void txtTrat21_TextChanged(object sender, EventArgs e)
            {
                txtCoroa22.Focus();
            }

            private void txtTrat22_TextChanged(object sender, EventArgs e)
            {
                txtCoroa23.Focus();
            }

            private void txtTrat23_TextChanged(object sender, EventArgs e)
            {
                txtCoroa24.Focus();
            }

            private void txtTrat24_TextChanged(object sender, EventArgs e)
            {
                txtCoroa25.Focus();
            }

            private void txtTrat25_TextChanged(object sender, EventArgs e)
            {
                txtCoroa26.Focus();
            }

            private void txtTrat26_TextChanged(object sender, EventArgs e)
            {
                txtCoroa27.Focus();
            }

            private void txtTrat27_TextChanged(object sender, EventArgs e)
            {
                txtCoroa28.Focus();
            }

            private void txtTrat28_TextChanged(object sender, EventArgs e)
            {
                btnAvanc.Focus();
            }

        #endregion

            private void Limpar_txt_Form()
            {
                txtCoroa28.Text = "0";
                txtCoroa27.Text = "0";
                txtCoroa26.Text = "0";
                txtCoroa25.Text = "0";
                txtCoroa24.Text = "0";
                txtCoroa23.Text = "0";
                txtCoroa22.Text = "0";
                txtCoroa21.Text = "0";
                txtRaiz28.Text = "0";
                txtRaiz27.Text = "0";
                txtRaiz26.Text = "0";
                txtRaiz25.Text = "0";
                txtRaiz24.Text = "0";
                txtRaiz23.Text = "0";
                txtRaiz22.Text = "0";
                txtRaiz21.Text = "0";
                txtTrat28.Text = "0";
                txtTrat27.Text = "0";
                txtTrat26.Text = "0";
                txtTrat25.Text = "0";
                txtTrat24.Text = "0";
                txtTrat23.Text = "0";
                txtTrat22.Text = "0";
                txtTrat21.Text = "0";
            }

            private void CondDent2_Activated(object sender, EventArgs e)
            {
                if (FormsMethods.Inicializa[FormsMethods.VetIndex])
                {
                    Limpar_txt_Form();
                    FormsMethods.Inicializa[FormsMethods.VetIndex] = false;
                    txtCoroa21.Focus();
                }
                if (FormsMethods.Altera.ToArray()[FormsMethods.VetIndex])
                {
                    FormsMethods.preencheForms();
                    FormsMethods.Altera[FormsMethods.VetIndex] = false;
                }
            }

            private void btnAvanc_Click(object sender, EventArgs e)
            {
                FormsMethods.nextForm();
            }

            






    }
}